import type { IQuery, IResponse, TableResponse } from '@/api/config/types';
import type { SCHEDULE_TYPE_ENUM } from '@/enum/system';
import axios from 'axios';

export interface PublishTime {
  start: string;
  end: string;
  work: string[];
  id: string;
  time: any;
}

export interface Material {
  name: string;
  second: number;
  url: string;
  id: string;
}

export interface Publicize {
  name: string;
  publicizeSize: string;
  materials: Material[];
  type: string;
  objects: string[];
  id?: string;
  publishTime: PublishTime[];
  timeZone: string;
  publishStatus: '1' | '0';
  timeType: SCHEDULE_TYPE_ENUM;
  week: any;
}

// 基本的请求配置
const prefix = '/publicize/publicize';

export const selectPublicizeById = (id: string | number) => {
  return axios.get<IResponse<Publicize>>(`${prefix}/${id}`);
};

export const listPublicize = (query?: IQuery) => {
  return axios.get<TableResponse<Publicize>>(`${prefix}/list`, { params: query });
};

export const createPublicize = (data: Publicize) => {
  return axios.post<IResponse>(prefix, data);
};

export const updatePublicize = (data: Publicize) => {
  return axios.put<IResponse>(prefix, data);
};

export const deletePublicize = (ids: (string | number)[]) => {
  return axios.delete<IResponse>(`${prefix}/${ids.join(',')}`);
};
